package com.xmmxjy.service;

import org.apache.activemq.ScheduledMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.stereotype.Service;

import javax.jms.Queue;
import javax.jms.TextMessage;

@Service
public class MqSendService {
    @Autowired
    private JmsMessagingTemplate jmsMessagingTemplate;
    @Autowired
    private Queue testQueue;

    /**
     * 发送测试
     * @param message
     */
    public void sendTest(String message) {
        JmsTemplate jmsTemplate = jmsMessagingTemplate.getJmsTemplate();
        //发送消息到队列
        jmsTemplate.send( testQueue, session -> {
            TextMessage textMessage =  session.createTextMessage(message);
            //	AMQ_SCHEDULED_DELAY 延迟投递的时间
            textMessage.setLongProperty(ScheduledMessage.AMQ_SCHEDULED_DELAY,10*1000);
            return textMessage;
        });
    }
}

